<?php

namespace ticket\modules\backend\models;

use Yii;

/**
 * This is the model class for table "dq_ticket_list".
 *
 * @property int $id
 * @property int $k_id 恐龙园id
 * @property string $price 价格
 * @property string $name 名称
 * @property int $status 1-显示 2-隐藏
 * @property string $activity_image 图片
 * @property string $activity_time 活动时间
 * @property string $activity_status 活动状态
 * @property string $activity_introduce 活动介绍
 * @property string $create_time 创建时间
 */
class DqTicketList extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'dq_ticket_list';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['k_id', 'price', 'name', 'status', 'create_time'], 'required'],
            [['k_id', 'status'], 'integer'],
            [['price'], 'number'],
            [['create_time'], 'safe'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'k_id' => 'K ID',
            'price' => 'Price',
            'name' => 'Name',
            'status' => 'Status',
            'create_time' => 'Create Time',
        ];
    }

    public function setInfo($data)
    {
        if (isset($data['id']) and !empty($data['id'])){
            $model = self::find()->where(['id' => $data['id']])->one();
            if (!is_null($model)){
                $model->price = $data['price'];
                $model->name = $data['name'];
                $model->status = $data['status'];
                $model->activity_name = $data['activity_name'];
                $model->activity_image = $data['activity_image'];
                $model->activity_time = $data['activity_time'];
                $model->activity_status = $data['activity_status'];
                $model->activity_introduce = $data['activity_introduce'];
                if ($model->save(0)){
                    return true;
                }
            }
        }
        return false;
    }

    public function getInfo($data)
    {
        if (isset($data['id']) and !empty($data['id'])){
            $model = self::find()->where(['id' => $data['id']])->asArray()->one();
        }else{
            $model = [];
        }
        return $model;
    }

    public function delInfo($data)
    {
        if (isset($data['id']) and !empty($data['id'])){
            $model = self::find()->where(['id' => $data['id']])->one();
            if (!is_null($model) and $model->delete()){
                return true;
            }
        }
        return false;
    }
}
